package samber

import (
	"fmt"
	"github.com/samber/lo"
)

func If() {
	result := lo.If(true, 1).
		ElseIf(false, 2).
		Else(3)
	fmt.Printf("%v\n", result) // 1
}

func IfF() {
	result := lo.IfF(true, func() int { return 1 }).
		ElseIfF(false, func() int { return 2 }).
		ElseF(func() int { return 3 })
	fmt.Printf("%v\n", result) // 1
}

// IndexOf 找第一次出现的下标
func IndexOf() {
	list := []int{0, 1, 2, 3, 4, 3}
	result := lo.IndexOf(list, 3)
	fmt.Printf("%v\n", result) // 3
}

// Interleave 循环交替输入切片
func Interleave() {
	result := lo.Interleave[int]([]int{1, 4, 7}, []int{2, 5, 8}, []int{3, 6, 9})
	fmt.Printf("%v\n", result) // [1 2 3 4 5 6 7 8 9]
}

// Intersect 返回交集
func Intersect() {
	list1 := []int{0, 1, 2, 3, 4, 3}
	list2 := []int{3, 4, 3}
	result := lo.Intersect(list1, list2)
	fmt.Printf("%v\n", result)
}

// Invert key、value交换 以为主第一次
func Invert() {
	kv := map[string]int{"foo": 1, "bar": 2, "baz": 3, "new": 3}
	result := lo.Invert(kv)
	fmt.Printf("%v\n", result) // map[1:foo 2:bar 3:baz]
}

// IsEmpty 零值
func IsEmpty() {
	demo := 0
	res1 := lo.IsEmpty(demo)
	var demo2 *foo
	res2 := lo.IsEmpty(demo2)
	var demo3 foo
	res3 := lo.IsEmpty(demo3)
	var demo4 = &foo{
		bar:  "",
		fill: "",
	}
	res4 := lo.IsEmpty(demo4)
	fmt.Printf("%v %v %v %v\n", res1, res2, res3, res4) // true true true false
}

func IsNotEmpty() {
	fmt.Println("我跟IsEmpty相反")
}

// IsSorted 是否满足排序
func IsSorted() {
	list := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	result := lo.IsSorted(list)
	fmt.Printf("%v\n", result) // true
}

func IsSortedByKey() {
	list := []string{"a", "bb", "ccc"}
	result := lo.IsSortedByKey(list, func(s string) int {
		return len(s)
	})
	fmt.Printf("%v\n", result) // true
}
